package com.uplooking.controller;

import com.alibaba.fastjson.JSON;
import com.uplooking.daomain.UserBean;
import com.uplooking.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class UserController extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String strValue =req.getParameter("value");//得到input输入框的值
        resp.setHeader("Content-Type", "text/html;charset=utf8");
//        System.out.println("str="+strValue);
        UserService service=new UserService();
        UserBean userBean=new UserBean();
        try {
            List<UserBean> users = service.getUsers(strValue);
            users.add(userBean);
            String jsonString = JSON.toJSONString(users);
            System.out.println(jsonString);
            resp.getWriter().write(jsonString);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
